﻿using Nova_Common;
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Material_MaterialTypeList : System.Web.UI.Page
{
    DataSet ds = new DataSet();
    //Nova_MOD.Menu Nova_MOD_Menu = new Nova_MOD.Menu();
    Nova_BLL.MaterialType Nova_BLL_MaterialType = new Nova_BLL.MaterialType();
    protected int iCount = 0;
    String strMessage = "";

    protected void Page_Load(object sender, EventArgs e)
    {
        ////LoginLogic.IsLogin();


        if (!IsPostBack)
        {
            gv_Bind();
        }
        if (this.hidden.Value != "") //保证添加修改页面回来后，刷新最新数据
        {
            gv_Bind();
        }
        this.hidden.Value = "";
    }

    /// <summary>
    /// 物料类别列表绑定
    /// </summary>
    protected void gv_Bind()
    {
        ds = Nova_BLL_MaterialType.ListMaterialType();
        gvMType.DataSource = ds;
        gvMType.DataBind();
    }

    protected void ibtnAdd_Click(object sender, ImageClickEventArgs e)
    {

    }

    protected void ibtnAllDel_Click(object sender, ImageClickEventArgs e)
    {

    }


    /// <summary>
    /// 删除  每行的单个删除按钮
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void ibtnDel_Click(object sender, ImageClickEventArgs e)
    {
        ImageButton ibtnDel = (ImageButton)sender;
        string TypeID = ibtnDel.CommandArgument.Trim().ToString(); ;

        if (!string.IsNullOrEmpty(TypeID))
        {
            try
            {
                iCount = Nova_BLL_MaterialType.DelMaterialType(TypeID, out strMessage);
                if (iCount > 0)
                {
                    ShowBox.MessageBox(this, "删除成功！");
                    gv_Bind();
                }
                else  //删除不成功 
                {
                    ShowBox.MessageBox(this, strMessage);
                    gv_Bind();
                }
            }
            catch (Exception ex)
            {
                Response.Write(ex.ToString());
            }
        }
    }


    protected void gvMType_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            ImageButton ibtnEdit = (ImageButton)e.Row.FindControl("ibtnEdit");
            string updateUrl = string.Format("javascript: document.getElementById('{2}').value=window.showModalDialog('MaterialTypeAddOrEdit.aspx?Mode={0}&TypeID={1}', window, 'dialogWidth=600px;dialogHeight=234px;scroll:no;resizable:no;status:0;');document.URL=location.href;", "Update", ibtnEdit.CommandArgument.Trim(), hidden.ClientID);
            ibtnEdit.Attributes.Add("onclick", updateUrl);

            //父类别 行显示颜色
            Label lbl_ParentTypeID = (Label)e.Row.FindControl("lbl_ParentTypeID");
            if (lbl_ParentTypeID.Text == "0")  //Command_detail表中存在显示红色，表示正在处理
            {
                //e.Row.ForeColor = Color.FromName("red");
                e.Row.BackColor = Color.AliceBlue;

            }
        }
    }

    protected void gvMType_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        gvMType.PageIndex = e.NewPageIndex;
        gv_Bind();  //重新绑定GridView

    }
}